/**
 * 
 */
package com.xpec.c4.service.module.datacenter.player;

import java.math.BigDecimal;

import com.ms.player.PlayerAttributeType;
import com.ms.player.PlayerUserType;
import com.ms.player.UpdateAttributeList;
import com.xpec.c4.db.dao.PlayerDAO;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.service.module.task.TaskAsyncCommand;

/**
 * 儲存玩家的錢到 db
 * 
 * @author TW15010
 */
public class UpdateH5PlayerMoneyToDbAsync extends TaskAsyncCommand {
	/**
	 * player id
	 */
	private GUID playerId = null;

	/**
	 * 身上的錢, 沒有變更就設 null
	 */
	private BigDecimal gold = null;

	/**
	 * 暫存錢包的錢, 沒有變更就設 null
	 */
	private BigDecimal tmpCash = null;

	public void initial(GUID playerId, BigDecimal gold, BigDecimal tmpCash) {
		this.playerId = playerId;
		this.gold = gold;
		this.tmpCash = tmpCash;
	}

	@Override
	public void asyncExecute() throws Exception {
		if (playerId == null) {
			return;
		}

		// 更新清單容器
		UpdateAttributeList updateList = new UpdateAttributeList();

		// 身上的錢
		if (gold != null) {
			updateList.addUpdateValue(PlayerAttributeType.GOLD_COIN, gold);
		}

		// 暫存錢包
		if (tmpCash != null) {
			updateList.addUpdateValue(PlayerAttributeType.TMP_CASH, tmpCash);
		}

		PlayerDAO.updatePlayerFromAttrList(playerId.toString(), updateList.getUpdateList(), PlayerUserType.PLAYER);
	}

	@Override
	public void execute() throws Exception {
	}
}
